package com.nothing.hessian.config;

import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.remoting.caucho.HessianProxyFactoryBean;

import com.nothing.hessian.service.CheckFaceService;

import lombok.Getter;
import lombok.Setter;

/**
 * <用于配置发布hessian接口> <这里只是做了最简单的配置，还可以设置超时时间，密码这些安全参数>
 * 
 * @author shíQíang㊚
 * @version 2019年6月6日10:17:37
 * @see [相关类/方法] (可选)
 **/
@Configuration
@ConfigurationProperties(prefix = "host") // 接收application.yml中的myProps下面的属性
@Getter
@Setter
public class HessionServiceConfig{
	
	public static List<String> camHost; 
	 
	private List<String> cam; // 接收prop1里面的属性值 
      
	public static String staticAppId;
	public static String staticSdkKey;
	public static Integer staticThreadPoolSize; 
	public static String staticHessionHost;
	public static String staticFileSavePath;
	
	@Value("${host.hession}")
	private String hession; 
	
	@Value("${config.freesdk.app-id}")
	public String appId;

	@Value("${config.freesdk.sdk-key}")
	public String sdkKey;

	@Value("${config.freesdk.thread-pool-size}")
	public Integer threadPoolSize;   
	
	@Value("${config.file.save.path}")
    public String fileSavePath;
	
	@PostConstruct
    public void init(){  
		camHost = cam; 
		staticAppId = appId;
		staticSdkKey = sdkKey;
		staticThreadPoolSize = threadPoolSize; 
		staticFileSavePath = fileSavePath;
    }
	 
	@Bean
    public HessianProxyFactoryBean checkClient() {
        HessianProxyFactoryBean factory = new HessianProxyFactoryBean();
        factory.setConnectTimeout(100000);
        factory.setReadTimeout(100000);
        factory.setOverloadEnabled(true);
        factory.setUsername("face");
        factory.setPassword("face"); 
        factory.setServiceUrl(hession+"/hessian/check.do");
        factory.setServiceInterface(CheckFaceService.class);
        return factory;
    }
}